public class demo02 {
    public static void main(String[] args) {
        int count=0;
        for (int i = 19000101; i <= 99991231; i++) {
            int tmp = i;
            int year = tmp / 10000;
            int month = tmp % 10000 / 100;
            int day = tmp % 100;
            int sum1 = 0;
            while (year != 0) {
                sum1 += year % 10;
                year /= 10;
            }
            int sum2 = 0;
            while (month != 0) {
                sum2 += month % 10;
                month /= 10;
            }
            while (day != 0) {
                sum2 += day % 10;
                day /= 10;
            }
            if (sum1 == sum2&&check(tmp)) {
                count++;
            }
        }
        System.out.println(count);
    }
    public static boolean checkmonth(int year){
        if((year%4==0&&year%100!=0)||(year%400==0)){
            return true;
        }
        return false;
    }
    public static boolean check(int num){
        int[] arr={0,31,28,31,30,31,30,31,31,30,31,30,31};
        int year=num/10000;
        int month=num%10000/100;
        int day=num%100;
        if(checkmonth(year)){
            arr[2]+=1;
        }
        if(month<1||month>12){
            return false;
        }
        if(day<1&&day>arr[month]){
            return false;
        }
        return true;
    }
}
